<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>找回密码</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="找回密码-收取验证码">
    <script type="text/javascript" src="../static/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="../static/res/layui/css/layui.css">
    <link rel="stylesheet" href="../static/res/css/global.css">
</head>

<jsp:include page="fly-head.jsp"></jsp:include>

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li class="layui-this">找回密码</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show" style="text-align: center">
                    <div style="margin: 0 auto;height: 120px">
                        <img src="/images/step3.png">
                    </div>
                    <div class="layui-form layui-form-pane" style="width: 450px;margin: 0 auto">
                        <form>

                            <div class="layui-form-item">
                                <label for="L_firstPassWord" class="layui-form-label">设置新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_firstPassWord" required lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>

                                <div class="layui-form-mid layui-word-aux">&nbsp&nbsp&nbsp&nbsp6到16个字符
                                    <span id="passWordNull" style="color: red; margin-left:5px; float:left;"></span>
                                </div>

                            </div>
                            <div class="layui-form-item">
                                <label for="L_secondPassWord" class="layui-form-label">重复新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_secondPassWord" required lay-verify="required"
                                           autocomplete="off" class="layui-input">

                                </div>
                                <span id="rePassNull" style="color: red; margin-left:5px; float:left;"></span>
                            </div>
                            <span id="showTrue" style="color: red; margin-left:190px; float:left;"></span>
                            <br></br>

                            <div class="layui-form-item">
                                <button class="layui-btn" alert="1" lay-filter="*" lay-submit
                                        onclick="ResetPassword();return false">重设密码
                                </button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="fly-footer.jsp"></jsp:include>

<script src="../static/res/layui/layui.js"></script>
<script>
    <%--获取url中参数--%>
    <%--检测密码格式--%>
    $('#L_firstPassWord').blur(function PassName() {
            if ($("#L_firstPassWord").val().length < 6 || $("#L_firstPassWord").val().length > 16) {
                $('#passWordNull').text("密码格式不正确");
                return false;
            }
            if ($("#L_firstPassWord").val().length > 5 && $("#L_firstPassWord").val().length < 17) {
                $('#passWordNull').text("");
                return false;
            }
        }
    );
    <%--检测密码是否一致--%>
    $('#L_secondPassWord').blur(function rePassName() {

            if ($("#L_secondPassWord").val() != $("#L_firstPassWord").val()) {
                $('#rePassNull').text("与原密码不一致");
                return false;
            }
            if ($("#L_secondPassWord").val() == $("#L_firstPassWord").val()) {
                $('#rePassNull').text("");
                return false;
            }
        }
    );

    function ResetPassword() {

        var L_firstPassWord = document.getElementById("L_firstPassWord").value;
        var L_secondPassWord = document.getElementById("L_secondPassWord").value;
        if ($("#L_firstPassWord").val() == "") {
            alert("密码不能为空");
            $("#L_firstPassWord").focus();
            return false;
        }
        ;
        if ($("#L_secondPassWord").val() == "") {
            alert("重复密码不能为空");
            $("#L_secondPassWord").focus();
            return false;
        }
        ;
        $.ajax({
            url: "/userAdmin/ResetPassword",
            type: "post",
            dataType: "json",
            data: {
                "firstPassWord": L_firstPassWord,
                "secondPassWord": L_secondPassWord
            },
            success: function (data) {
                if (data.msg == "修改成功") {
                    window.location.href = "/admin/adminForgetSet4.jsp"
                } else if (data.msg == "密码格式不正确") {
                    alert("密码格式不正确");
                } else if (data.msg == "两次输入密码不相同") {
                    alert("两次输入密码不相同");
                } else if (data.msg == "服务器出现错误，请稍后重试") {
                    alert("服务器出现错误，请稍后重试");
                }

            }
        });
    }


</script>

</body>
</html>